﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmedQuery", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedQuery))]
    public class DetailandmedQuerySerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedQuery clazz;
        
        public DetailandmedQuerySerializer(IDetailandmedQuery clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Arinimi!=null) {
                Writer.WriteStartElement("arinimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AriregistriKood!=null) {
                Writer.WriteStartElement("ariregistri_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsukohtEttevotjaAadressis!=null) {
                Writer.WriteStartElement("asukoht_ettevotja_aadressis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsukohtEttevotjaAadressis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HaldyksusEttevotjaAadressis!=null) {
                Writer.WriteStartElement("haldyksus_ettevotja_aadressis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.HaldyksusEttevotjaAadressis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.FyysiliseIsikuEesnimi!=null) {
                Writer.WriteStartElement("fyysilise_isiku_eesnimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.FyysiliseIsikuEesnimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.FyysiliseIsikuPerekonnanimi!=null) {
                Writer.WriteStartElement("fyysilise_isiku_perekonnanimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.FyysiliseIsikuPerekonnanimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.FyysiliseIsikuSynniaeg!=null) {
                Writer.WriteStartElement("fyysilise_isiku_synniaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.FyysiliseIsikuSynniaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.FyysiliseIsikuKood!=null) {
                Writer.WriteStartElement("fyysilise_isiku_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.FyysiliseIsikuKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.FyysiliseIsikuRollJada!=null) {
                Writer.WriteStartElement("fyysilise_isiku_roll_jada");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.FyysiliseIsikuRollJada.Count);
                for (int x = 0; ((clazz.FyysiliseIsikuRollJada != null) 
                            && (x < clazz.FyysiliseIsikuRollJada.Count)); x = (x + 1)) {
                    if (clazz.FyysiliseIsikuRollJada[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.FyysiliseIsikuRollJada[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("yandmed");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Yandmed))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("iandmed");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Iandmed))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("kandmed");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Kandmed))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("dandmed");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Dandmed))).ToString());
            Writer.WriteEndElement();
            if (clazz.AinultKehtivad!=null) {
                Writer.WriteStartElement("ainult_kehtivad");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.AinultKehtivad))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Staatused!=null) {
                Writer.WriteStartElement("staatused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.Staatused.Count);
                for (int x = 0; ((clazz.Staatused != null) 
                            && (x < clazz.Staatused.Count)); x = (x + 1)) {
                    if (clazz.Staatused[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Staatused[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Keel!=null) {
                Writer.WriteStartElement("keel");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Keel))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Evarv!=null) {
                Writer.WriteStartElement("evarv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Evarv))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            if (Reader.LocalName=="asukoht_ettevotja_aadressis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>asukoht_ettevotja_aadressis");
                }
                clazz.AsukohtEttevotjaAadressis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("asukoht_ettevotja_aadressis")).Value;
            }
            if (Reader.LocalName=="haldyksus_ettevotja_aadressis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>haldyksus_ettevotja_aadressis");
                }
                clazz.HaldyksusEttevotjaAadressis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("haldyksus_ettevotja_aadressis")).Value;
            }
            if (Reader.LocalName=="fyysilise_isiku_eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>fyysilise_isiku_eesnimi");
                }
                clazz.FyysiliseIsikuEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("fyysilise_isiku_eesnimi")).Value;
            }
            if (Reader.LocalName=="fyysilise_isiku_perekonnanimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>fyysilise_isiku_perekonnanimi");
                }
                clazz.FyysiliseIsikuPerekonnanimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("fyysilise_isiku_perekonnanimi")).Value;
            }
            if (Reader.LocalName=="fyysilise_isiku_synniaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>fyysilise_isiku_synniaeg");
                }
                clazz.FyysiliseIsikuSynniaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("fyysilise_isiku_synniaeg")).Value;
            }
            if (Reader.LocalName=="fyysilise_isiku_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>fyysilise_isiku_kood");
                }
                clazz.FyysiliseIsikuKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("fyysilise_isiku_kood")).Value;
            }
            if (Reader.LocalName=="fyysilise_isiku_roll_jada") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>fyysilise_isiku_roll_jada");
                }
                clazz.FyysiliseIsikuRollJada = new System.Collections.Generic.List<System.String>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("fyysilise_isiku_roll_jada");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_paring_rollid>item");
                        }
                        clazz.FyysiliseIsikuRollJada.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="yandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>yandmed");
                }
                clazz.Yandmed = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("yandmed")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmedQuery>yandmed", Reader.LocalName);
            }
            if (Reader.LocalName=="iandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>iandmed");
                }
                clazz.Iandmed = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("iandmed")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmedQuery>iandmed", Reader.LocalName);
            }
            if (Reader.LocalName=="kandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>kandmed");
                }
                clazz.Kandmed = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("kandmed")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmedQuery>kandmed", Reader.LocalName);
            }
            if (Reader.LocalName=="dandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>dandmed");
                }
                clazz.Dandmed = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("dandmed")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmedQuery>dandmed", Reader.LocalName);
            }
            if (Reader.LocalName=="ainult_kehtivad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>ainult_kehtivad");
                }
                clazz.AinultKehtivad = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("ainult_kehtivad")).Value;
            }
            if (Reader.LocalName=="staatused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>staatused");
                }
                clazz.Staatused = new System.Collections.Generic.List<System.String>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("staatused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_paring_staatused>item");
                        }
                        clazz.Staatused.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="keel") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>keel");
                }
                clazz.Keel = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("keel")).Value;
            }
            if (Reader.LocalName=="evarv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmedQuery>evarv");
                }
                clazz.Evarv = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("evarv")).Value;
            }
        }
    }
}
